﻿using Cms.Domain.Authentication;
using iLib.Web.UI;

namespace Cms.Web.Framework.Controls
{
    public class AdminPopupBasePage : System.Web.UI.Page
    {
        public string UserPhysicalTempDirectory
        {
            get { return "Admin\\Resources\\Temp\\" + AdministratorID + "\\"; }
        }

        public string UserTempDirectory
        {
            get { return Url.FullPath + "Admin/Resources/Temp/" + AdministratorID + "/"; }
        }

        public virtual int AdministratorID
        {
            get
            {
                AuthenticatedUser user = Conversion.ToAuthenticatedUser(User.Identity.Name);
                return user.AdministratorID;
            }
        }

        public void RedirectToPermissionDeniedPage()
        {
            RedirectToPermissionDeniedPage(null);
        }
        
        public void RedirectToPermissionDeniedPage(string message)
        {
            string url = "~/Admin/PermissionDenied.aspx";
            if (message != null)
                url += "?message=" + Server.UrlEncode(message);
            Response.Redirect(url);
        }

        public void RedirectToBadRequestParameterPage()
        {
            Response.Redirect("~/Admin/BadRequestParameter.aspx");
        }
    }
}